home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga News 95
/
Amiga News 95.iso
/
dpat
/
dpat05
/
find
/
find.doc
< prev
next >
Wrap
Text File
|
1990-01-17
|
8KB
|
205 lines
NAME
find (this doc for v3.9b)
SYNOPSIS
find -[acgsv] <root dir> <pattern>
FUNCTION
Searches a directory and its subdirectories for the pattern
INPUTS
-[acgsv] Options (see below)
<root dir> Any valid AmigaDos directory name
<pattern> A (very) restricted regular expression
RESULTS
Displays the name(s) found on standard output, and maybe more
depending on the options invoked
KNOWN BUGS
If the -g option is used, the Shell prompt function %S will not
be updated. This can be achieved by calling CD after find.
Find
----
November, 21st 1989 Author: Cédric BEUST
* A few lines to describe how it works
--------------------------------------
In fact, I did my best so that my command does not need any documentation
to be used. This is due to the fact that I bothered a lot
when I tried to master the CLI for the first time since no documentation
at all was available at this time (ugh! Looks like prehistoric age!). I DO
THINK that any command should be self-explanatory. Commodore programmers,
do you hear me?
All right, I said what I had to, so let's come to it.
The initial idea was to have a Unix-like find command on Amiga. This
has never been supplied by Commodore and I have always wondered why.
Recently, I decided that I had wondered enough and I started programming
it. The result is far from having all the Unix' find possibilities, but
though, it helped me a lot (anyway, Unix' one has a lot of features which
nobody never uses. Commodore's ones as well).
If you type 'find' with nothing at all, or with wrong parameters or
with a '?', you'll get the following lines (approximately):
Find (v3.9b) - Recursive search of files
Copyright Cédric BEUST - NICE (France)
Usage: find -[acgv] <source dir> <pattern>
Options:
-a: Don't stop at first occurence
-c: Don't ignore case
-g: Change to directory found
-s: Stop as soon as something is found
-v: Display search steps
Wildcards: ? (any character), # (none or several times) and * (anything)
To abort search, type CTRL-C
Isn't all that self-explanatory? As a matter of fact, it is. But yet,
I will add a few things.
* Syntax
--------
- The options
So far, there are five options:
-a:
Means that when a file is found, find doesn't stop and keeps on
searching until it has searched all the directories. This is
useful if you know that the name you are searching might be found
in several directories. NOTE: this option is automatically set if
you use a pattern. The reason why I did this is simple: if you
use a pattern, then you can't tell whether the first name that
will appear is the one you are looking for or not. And you
wouldn't like the program to stop at this point, would you?
-c:
By default, find will ignore letter case, i.e.
find jh0: test
will either match 'test' (of course!), 'Test', 'TESt', and so on.
With the -c flag on, only 'test' will be found.
-g:
This feature is especially useful in scripts. It makes a CD to the
found directory. This allows to do something to the name found
after it has been found (for example, deleting it). For instance,
using it with the -s flag could produce a little shell script that
might delete all the hated .fastdir throughout your hard disk.
Good idea, isn't it?
-v:
This is for your eye's pleasure! It merely displays the
directories it is scanning with an indentation in order to get
an idea of the hierarchy of the disk searched (and also to prove
that it is well doing what you expect!).
-s:
This one forces find to stop after the
first name found, bypassing what I said a few lines above. You
will surely object that this option is redundant with the -a
one, but I don't think so and I have a good reason for that.
Suppose you want to write a script that deletes all the .fastdir
on your hard disk (the idea is not mine but Cedric's. Yeah,
another one). You use a 'find -g jh0: .fastdir' and as soon as
it is found, you delete it and you loop. OK. But suppose you want
to delete a pattern... For example, all the .bak. Then, you have
to force find to stop after each occurence it gets. That's what
the -s option does. On the opposite, suppose that by default,
find stops ALWAYS as soon as it finds something, and suppose
there is an option to force it to continue. Will you always think
to use this option when looking for a pattern? I don't think I
will. So I prefer this solution.
- The source dir
No need to write long about that. Any device name will do, even
an 'assign'ed one (jh0:, df0:, mydir:, jh2:lib, etc...). This will
be the root directory, and find will then scan all its directories
and subdirectories.
- The pattern
It may be a simple name or a pattern. This pattern follows
AmigaDos' weird conventions about this: only # and ? are accepted
in this version (3.9 as I am writing) and not ()|. So far, I didn't
find it was a big lack although I might need users' opinion. In
earlier versions of find, the wildcards used to be ? and *, which I
find much more convenient, and I don't think the reason is just a
matter of type saving (* takes one less key than #?, had you
noticed?). Has anyone out there ever used the # character with
something else than '?'? So why bother with this notation? Anyway, I
decided to stick to it since I'd like my command to have its place
in any c: directory. Let's see a few examples of pattern matching:
a?c --> abc acc adc...
a#bc --> ac abc abbc abbbc...
a#?.c --> a.c asadf.c aer.c...
You see? I'll stop with these examples but I'm quite confident that
my pattern matching routine will work correctly even in the worst
cases (believe me, I've tested it quite a bit!). Anyway, I found
out that I rarely use something else than the ones I just
described.
-- Addendum for v3.9b: the * wildcard has been added. The previous ones
still remain.
A CTRL-C may be used at any time to abort search. I bet you'll find this
feature useful when find is entering the depths of your directory and it
has already given you the name you were looking for!
* One last thing
----------------
And this one deserves a special chapter since it is not said in the help
menu (nobody is perfect! But don't criticize or I'll add it in next
versions): if ever find couldn't find any file matching the pattern, it
will send a return code of 5 (it is a WARN code). This is useful in
scripts to know when find is finished with its work: all you have to do is
to include a 'IF WARN SKIP END ELSE...' and it will not loop forever.
;-{
In the current version (3.9b), I still haven't figured out how to impose
the new current directory to this #?!#@ %S prompt. It's really getting on my
nerves.
:-)
Well! Looks like I wrote a bit more than what I thought. And yet, it is
a soooo short command! There will be probably other versions, depending on
the suggestions I am made (this is for YOU!). But I can already announce
that there will probably be a Workbench version of this function (alike
Mac's one). But this will take much more work to do.
A few thanks to all the ones who helped me improve this command and add
new options, and mainly: Cédric Nérot (for Guru proof thorough testing and
the .fastdir application program), Jean-Charles Godien (special thanks to
him! Nifty pattern matching routine, JC!), Pierre Ardichvili (sharp-witted
suggestions) and Bruce Lepper (alpha, beta, gamma, ... and other-greek-
letters versions tester despite him).
Enjoy!
You can send me your suggestions to this address:
BEUST Cédric
"Prométhée"
80 Av. du Bois de Cythère
06000 NICE
FRANCE
Tél. 93 96 00 23